import java.util.Scanner;

/*
  @author: 13813
  @date: 2024/11/11 9:04
*/
public class HomeWork11 {
    public static int addStu(Scanner scanner1, String[][] arr1, int index1) {
        String[] stu = new String[3];
        System.out.println("请输入姓名");
        stu[0] = scanner1.nextLine();

        System.out.println("年龄");
        stu[1] = scanner1.nextLine();

        System.out.println("性别");
        stu[2] = scanner1.nextLine();

        arr1[index1] = stu;

        index1++;
        return index1;
    }

    public static void main(String[] args) {
        //输出语句，控制台
        System.out.println("请输入用户名");
        //接收用户输入
        Scanner scanner = new Scanner(System.in);
        //用户名字符串数据
        String userName = scanner.nextLine();
        System.out.println("请输入密码");
        //密码字符串数据
        String passwd = scanner.nextLine();
        if (userName.equals("zhangsan") && passwd.equals("123")) {
            boolean flag = true;
            String[][] arr = new String[50][3];
            int index = 0;
            do {
                System.out.println("1.新增2.修改3.删除4.查询5.退出");
                String choice = scanner.nextLine();

                switch (choice) {//姓名 年龄 性别
                    case "1":
                        index = addStu(scanner, arr, index);
                        break;
                    case "2":
                        //提示用户输入姓名
                        System.out.println("请输入姓名");
                        //接收用户用户输入姓名
                        //存储用户输入的姓名
                        //根据用户输入的姓名查找那个用户
                        //如果查到了，提示用户输入年龄
                        //接收用户输入的年龄
                        //修改此用户的年龄
                        String updateName = scanner.nextLine();
                        for (int i = 0; i < index; i++) {
                            if (updateName.equals(arr[i][0])) {
                                System.out.println("请输入年龄");
                                String updateAge = scanner.nextLine();
                                arr[i][1] = updateAge;
                            }
                        }
                        break;
                    case "3":
                        System.out.println("请输入要删除的姓名");
                        String delName = scanner.nextLine();
                        for (int i = 0; i < index; i++) {
                            if (arr[i] != null) {
                                if (delName.equals(arr[i][0])) {
                                    arr[i] = null;
                                }
                            }
                        }
                        break;
                    case "4":
                        for (int i = 0; i < index; i++) {
                            if (arr[i] != null) {
                                System.out.println("姓名:" + arr[i][0]);
                                System.out.println("年龄:" + arr[i][1]);
                                System.out.println("性别:" + arr[i][2]);
                            }
                        }
                        break;
                    case "5":
                        //改成false
                        flag = false;
                        System.out.println("退出");
                        break;
                }
            } while (flag);

        } else {
            System.out.println("登录失败");
        }
    }
}
